** This do file merges and processes the data from HYDE 3.1

* The underlying data has been generated using the raster data from HYDE 3.1 of 1400-1900 in the following way
* Zonal statistics as Table in ArcGIS using the 0.1x0.1 grid shapefile <Grid_0_1x0_1_WGS1984.shp>, Projection WGS 1984
* .dbf saved as excel in Excel

use "Grid Africa\Files\grid_gridcell.dta", replace // contains set of gridcell ids
save "Grid Africa\Files\grid_pop.dta", replace

forval f=1400(100)1900 {
// 1. Import excel files
	clear
	import excel "Grid Africa\Files\pop`f'.xlsx", sheet("pop`f'") firstrow case(lower)
	drop objectid zone_code count area min max range std
	rename mean mpop`f'
	rename sum spop`f'
	rename descriptio gridcell
	label var mpop`f' "Mean population of `f' (Source: HYDE 3.1) "
	label var spop`f' "Sum of population `f' (Source: HYDE 3.1)"
	// 2. Merge with other pop data
	merge 1:1 gridcell using "Grid Africa\Files\grid_pop.dta"
	replace mpop`f'=0 if mpop`f'==.
	replace spop`f'=0 if spop`f'==.
	drop _merge
// 3. Save
	save "Grid Africa\Files\grid_pop.dta", replace
}

